import {Component, OnInit} from '@angular/core';
import {fromEvent} from 'rxjs';
import {CommonService} from '../common.service';

@Component({
    selector: 'app-footer',
    templateUrl: './footer.component.html',
    styleUrls: ['./footer.component.css']
})
export class FooterComponent implements OnInit {
    channel = this.Service.getChannel();
    back2top_hide = 'hide';

    constructor(private Service: CommonService) {
    }

    goTop() {
        let timer;
        cancelAnimationFrame(timer);
        timer = requestAnimationFrame(function fn() {
            const oTop = document.body.scrollTop || document.documentElement.scrollTop;
            if (oTop > 0) {
                scrollBy(0, -100);
                timer = requestAnimationFrame(fn);
            } else {
                cancelAnimationFrame(timer);
            }
        });
    }

    ngOnInit() {
        fromEvent(window, 'scroll').subscribe((event) => {
            if (scrollY < 700) {
                this.back2top_hide = 'hide';
            } else {
                this.back2top_hide = '';
            }
        });
    }
}
